/*
 * ----------------------------------------------------------------------------
 * File Name: CLA_4bit
 * Author: Aeriff
 * Date Created: 2025.3.4
 * Last Modified: 2025.3.4
 * Description: A 4-bit Carry Lookahead Adder
 * ----------------------------------------------------------------------------
*/

`timescale 1ns/1ps

module CLA_4bit (
    input [3:0] A,
    input [3:0] B,
    input Cin,

    output [3:0] Sum,
    output Cout
);
    
    wire [3:0] C;

    wire [3:0] G = A & B;
    wire [3:0] P = A | B;

    assign C[0] = G[0] || P[0] & Cin;
    assign C[1] = G[1] || P[1] & G[0] || P[1] & P[0] & Cin;
    assign C[2] = G[2] || P[2] & G[1] || P[2] & P[1] & G[0] || P[2] & P[1] & P[0] & Cin;
    assign C[3] = G[3] || P[3] & G[2] || P[3] & P[2] & G[1] || P[3] & P[2] & P[1] & G[0] || P[3] & P[2] & P[1] & P[0] & Cin;

    assign Sum[0] = A[0] ^ B[0] ^ Cin;
    assign Sum[1] = A[1] ^ B[1] ^ C[0];
    assign Sum[2] = A[2] ^ B[2] ^ C[1];
    assign Sum[3] = A[3] ^ B[3] ^ C[2];

    assign Cout = C[3];


endmodule